package cn.edu.tsinghua.mutimedia.util;

import java.io.File;
import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class Conf {
	  public static final String LOCAL_VIDEO_DIR = "/home/hadoop/work/film/";
	  public static final String LOCAL_IMAGE_INDEX = "/home/hadoop/work/index/";
	  public static final String LOCAL_AUDIO_DIR = "/home/hadoop/work/audio/";
	  public static final String LOCAL_IMAGE_DIR = "/home/hadoop/work/image/";
	  
	  static{
				File videoPath = new File(LOCAL_VIDEO_DIR);
			    if (!(videoPath.exists()))
			    {
			    	videoPath.mkdirs();
			    }
			    File indexPath = new File(LOCAL_IMAGE_INDEX);
			    if (!(indexPath.exists()))
			    {
			    	indexPath.mkdirs();
			    }
			    File audioPath = new File(LOCAL_AUDIO_DIR);
			    if (!(audioPath.exists()))
			    {
			    	audioPath.mkdirs();
			    }
			    File imagePath = new File(LOCAL_IMAGE_DIR);
			    if (!(imagePath.exists()))
			    {
			    	imagePath.mkdirs();
			    }
	  }
	  
	  public static void copyToLocal(String source)
	  {
	  	Configuration config = new Configuration();
	    FileSystem hdfs;
		try {
			hdfs = FileSystem.get(config);
		    Path path = new Path(source);
		    hdfs.copyToLocalFile(path, new Path(LOCAL_VIDEO_DIR));
		} catch (IOException e) {
			e.printStackTrace();
		}
	   
	  }
}
